<template>
    <div class="content">
        <div class="typeArea">
            <el-form :label-position="labelPosition" label-width="80px" :model="formLabelAlign">
                <el-form-item label="小说ID">
                    <el-input name='bookId' v-model="formLabelAlign.bookId" :disabled="true"></el-input>
                </el-form-item>
                <el-form-item label="小说名">
                    <el-input name='bookName' v-model="formLabelAlign.bookName" ></el-input>
                </el-form-item>
                <el-form-item label="小说类型">
                    <el-input name='style' v-model="formLabelAlign.style"></el-input>
                </el-form-item>
                <el-form-item label="小说简介">
                    <el-input name='introduct' v-model="formLabelAlign.introduct"></el-input>
                </el-form-item>
                <el-form-item label="小说状态">
                    <el-input name='status' v-model="formLabelAlign.status"></el-input>
                </el-form-item>
                <el-form-item label="关注度">
                    <el-input name='focusCount' v-model="formLabelAlign.focusCount" :disabled="true"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="sendEditeBookData()">提交</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>
<script>
    import {vm,key1} from './commonComponents/connect.vue';
    vm.$on(key1,function (editeBookId) {
        this.$http.get('http://localhost/api/getInitBookData/'+editeBookId).then(function(result){
            document.querySelector('input[name="bookId"]').value = result.body[0].bookId;
            document.querySelector('input[name="bookName"]').value = result.body[0].bookName;
            document.querySelector('input[name="style"]').value = result.body[0].style;
            document.querySelector('input[name="introduct"]').value = result.body[0].introduct;
            document.querySelector('input[name="status"]').value = result.body[0].status;
            document.querySelector('input[name="focusCount"]').value = result.body[0].focusCount;
        })
    })
    export default {
        data() {
            return {
                labelPosition: 'right',
                editeBookId:'',
                formLabelAlign: {
                    bookId: '',
                    bookName: '',
                    style: '',
                    introduct: '',
                    status: '',
                    focusCount: '',
                }
            };
        },
        methods:{
            sendEditeBookData:function(){
                let bookId = document.querySelector('input[name="bookId"]').value;
                this.$http.post('http://localhost/api/sendEditeBookData/'+bookId,
                    {
                        bookId:bookId,
                        bookName:this.formLabelAlign.bookName,
                        style:this.formLabelAlign.style,
                        introduct:this.formLabelAlign.introduct,
                        status:this.formLabelAlign.status
                    }, {emulateJSON:true})
                    .then(function(result){
                        this.$router.push({path:'/app/bookManager'});
                })
            }
        },
        created:function(){

        }
    }
</script>
<style scoped>
    .content{
        width: 100%;
        padding: 20px;;
    }
    .content>.typeArea{
        width: 500px;
        margin-left:50px;
    }
</style>